package leetcode100;

import java.util.ArrayList;
import java.util.List;

public class lc045 {
    public static void main(String[] args) {
        int[] nums = new int[]{1,2,3};
        new lc045().subsets(nums);
    }

    public List<List<Integer>> subsets(int[] nums) {
        List<List<Integer>> res = new ArrayList<>();
        for (int i = 0; i <= nums.length; i++) {
            backtrace(res, new ArrayList<>(),0,i, nums);
//            System.out.println("res = " + res);
        }


        return res;

    }

    public void backtrace(List<List<Integer>> res,List<Integer> cur,int index,int size,int[] nums) {
        if (cur.size()==size) {
            res.add(new ArrayList<>(cur));
            return ;
        }

        for (int i = index; i < nums.length; i++) {
            cur.add(nums[i]);
            backtrace(res,cur,i+1,size,nums);
            cur.remove(cur.size()-1);
        }
    }
}
